package cn.aukw.todolist.sqlite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class SQLiteHelper extends SQLiteOpenHelper {
    public static final String DB_NAME = "todolist.db";
    private static final int DB_VERSION = 2;
    public static final String LIST_NAME = "list";


    public SQLiteHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE IF NOT EXISTS " + LIST_NAME
                + "("
                + "id INTEGER PRIMARY KEY AUTOINCREMENT, "
                + "title VARCHAR, "      // 事件标题
                + "content VARCHAR, "   // 事件内容
                + "time VARCHAR, "        // 保存事件的时间
                + "isCompleted INTEGER DEFAULT 0" // 是否完成，0 表示未完成，1 表示已完成
                + ")");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if (oldVersion < 2) {
            db.execSQL("ALTER TABLE " + LIST_NAME + " ADD COLUMN isCompleted INTEGER DEFAULT 0");
        }
    }
}
